$.WindowView = function(options) {
	var window_id = options.id||"top_window";
	var window_view = options.view;
	var form_action = options.action;
	var options = $.extend({
			title:"标题",
			width:800,
			height:600,
			href:"",//窗口跳转的地址
			action:null,//窗口下提交表单对应的Action地址
			modal:true,
			id:window_id,//弹出窗的ID
			view:null,   //上级视图ID，如果存在的话，保存之后会自动刷新页面
			buttonShow:false,  //是否显示窗口右下角确定和取消按钮
			formData:null, //打开新窗口之后，当前表单默认加载的数据。
			paramFlag:false,//false的是FormData，true取的是datagrid参数里面的值
			onClose:function(){
				
			},
			buttons: [{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					var iJquery = $('#'+window_id+" iframe")[0].contentWindow.jQuery;
					iJquery("form:first").form("submit",{    
						url:form_action,
					    onSubmit: function(){    
					    	return iJquery(this).form('validate');
					    },    
					    success:function(data){ 
					    	
					    	if(data){
					    		var d = null;
					    		if(typeof data == "string"){
						    		d = $.parseJSON(data)
						    	}else if(typeof data == "object"){
						    		d = data;
						    	}
					    		if(d.error){
						    		parent.$.messager.show({ title : "提示",msg: d.error.message, position: "bottomRight" });
						    	}else{
						    		if(window_view!=null){
							    		window_view.reload();
							    	}
									$('#'+window_id).dialog("close");
									parent.$.messager.show({ title : "提示",msg: "操作成功", position: "bottomRight" });
						    	}
					    	}else{
					    		if(window_view!=null){
						    		window_view.reload();
						    	}
								$('#'+window_id).dialog("close");
								parent.$.messager.show({ title : "提示",msg: "操作成功", position: "bottomRight" });
					    	}
					    	
					    }    
					});
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(a,b,c){
					$('#'+window_id).dialog("close");
				}
			}],
			onClose:function(){},//关闭之后回调方法
		}, options);
	var href = options.href;
	if(options.formData){
		href =href+"?"+options.key+"="+options.formData[options.key];
	}
	var content = $('<iframe src="'+href+'" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>');  
    var boarddiv = '<div id="'+options.id+'" title="' + options.title + '" style="overflow:hidden";></div>'//style="overflow:hidden;"可以去掉滚动条  
    $(document.body).append(boarddiv);  
	$(content).bind("load",function(){
		if(options.formData){
			var iJquery = $('#'+window_id+" iframe")[0].contentWindow.jQuery;
			iJquery("form:first").form("load",options.formData);
		}
	});
	
    var win = $('#'+options.id).dialog({  
        content: content,  
        width: options.width,  
        height: options.height,  
        modal: options.modal,  
        title: options.title,  
        buttons: options.buttonShow?options.buttons:[],  
        onClose: function () {  
            options.onClose(this);
            $(this).dialog('destroy');
        }
    });  
    win.dialog('open');  
    return window_view;
}
$.fn.submitForm = function (options) {
	//提交表单
	$(this).form("submit",{    
		url:basePath+"/user/add",
	    onSubmit: function(){    
	    	return $(this).form('validate');
	    },    
	    success:function(data){   
	    	successTip(data,dg,d);
	    }    
	}); 
}

